package app.auto.runner.base;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import app.auto.runner.base.intf.ListBuilder;

public class SubUtil {
    public static List getSub(List maplist, String name, Object value, String method) {
        List rt = new ArrayList();
        if (value == null) {
            value = "";
        }
        for (int i = 0; i < maplist.size(); i++) {
            Object object = maplist.get(i);
            ;
            String pervalue = null;
            if (object instanceof Map) {
                Map m = (Map) object;
                pervalue = m.get(name) + "";
            }
            if (method.toLowerCase().equals("equals")) {

                if (pervalue.equals(value) || value.equals("")) {
                    rt.add(object);
                }
            } else if (method.toLowerCase().equals("contains")) {
                if (pervalue.contains(value.toString()) || value.toString().equals("")) {
                    rt.add(object);
                }
            } else if (method.contains("starts")) {
                if (value instanceof List) {


                    List turnparams = ((List) value);
                    if (value instanceof List) {
                        for (Object ps : turnparams) {
                            if (pervalue.replace("android:","").startsWith(ps.toString())) {
                                rt.add(object);
                            }
                        }
                    }
                }
            }
        }
        return rt;
    }

}
